package com.jrx.anytxn.reporting.job.xib.step;

import com.jrx.anytxn.common.uitl.DateUtils;
import com.jrx.anytxn.reporting.mapper.ext.ExtAmlIATradingMapper;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobExecutionListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class MockTradingListener implements JobExecutionListener {


    @Resource
    private ExtAmlIATradingMapper extAmlIATradingMapper;

    final String MOCK_KEY = "mock.today";

    @Autowired
    Environment env;


    @Override
    public void beforeJob(JobExecution jobExecution) {
        final String todayStr = env.getProperty(MOCK_KEY, String.class);
        if (StringUtils.isEmpty(todayStr)) {
            throw new RuntimeException(MOCK_KEY + "不能为空");
        }
        Date today = DateUtils.parseDate(todayStr, "yyyy-MM-dd");
        extAmlIATradingMapper.deleteByEtlDt(today);
    }

    @Override
    public void afterJob(JobExecution jobExecution) {

    }

}
